package JFrame;

import serive.UserService;
import serive.UserServiceImpl;

import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.*;

/**
 * @author DONG
 */
public class LonginJFrame {
	UserService userService;
	private JFrame frame;
	private JTextField textField_1,textField_2;


	public LonginJFrame() {
		initialize();
		frame.setVisible(true);
	}

	private void initialize() {
		userService =new UserServiceImpl();
		frame = new JFrame();
		frame.getContentPane().setBackground(new Color(27, 217, 202, 255));
		frame.setBounds(100, 100, 861, 538);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		JLabel lblNewLabel = new JLabel("欢迎进入游戏库");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setFont(new Font("宋体", Font.PLAIN, 41));
		lblNewLabel.setForeground(Color.BLACK);
		lblNewLabel.setBounds(153, 33, 510, 55);
		frame.getContentPane().add(lblNewLabel);
		
		JLabel lblNewLabel_1 = new JLabel("用户名：");
		lblNewLabel_1.setFont(new Font("宋体", Font.PLAIN, 19));
		lblNewLabel_1.setBounds(181, 135, 115, 55);
		frame.getContentPane().add(lblNewLabel_1);

		textField_1 = new JTextField();
		textField_1.setToolTipText("");
		textField_1.setText("输入用户名");
		textField_1.setBackground(SystemColor.window);
		textField_1.setBounds(254, 147, 353, 35);
		frame.getContentPane().add(textField_1);
		textField_1.setColumns(30);

		JLabel lblNewLabel_2 = new JLabel("密码：");
		lblNewLabel_2.setFont(new Font("宋体", Font.PLAIN, 19));
		lblNewLabel_2.setBounds(181, 185, 115, 55);
		frame.getContentPane().add(lblNewLabel_2);

		textField_2 = new JTextField();
		textField_2.setToolTipText("");
		textField_2.setText("输入密码");
		textField_2.setBackground(SystemColor.window);
		textField_2.setBounds(254, 197, 353, 35);
		frame.getContentPane().add(textField_2);
		textField_2.setColumns(30);

		JButton btnNewButton = new JButton("登入");
		btnNewButton.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				String id = textField_1.getText();
				String pwd = textField_2.getText();
				userService =new UserServiceImpl();
				boolean login = userService.login(id, pwd);
				if (login){
					new StartJFrame(id);
				}else {
					JOptionPane.showMessageDialog(frame.getContentPane(),
							"用户名或密码错误", "！！！",JOptionPane.WARNING_MESSAGE);
				}
			}
		});

		btnNewButton.setForeground(Color.BLACK);
		btnNewButton.setBounds(320, 250, 175, 31);
		frame.getContentPane().add(btnNewButton);
		JButton btnNewButton2 = new JButton("去注册");
		btnNewButton2.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				new RegisterJframe();
			}
		});
		btnNewButton2.setForeground(Color.BLACK);
		btnNewButton2.setBounds(320, 300, 175, 31);
		frame.getContentPane().add(btnNewButton2);
	}
}
